"""
公共基础数据服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.base_data import (
    BankListRequest, BankListResponse,
    BankBranchListRequest, BankBranchListResponse,
    MccQueryRequest, MccQueryResponse,
    RegionListRequest, RegionListResponse,
    BankCardBinMatchingRequest, BankCardBinMatchingResponse
)


class BaseDataService(BaseService):
    """公共基础数据服务类"""
    
    def __init__(self, config):
        """
        初始化公共基础数据服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的完整API路径
        api_url = getattr(request_class, 'API_URL', '')
        
        if not api_url:
            # 如果没有定义API_URL，使用默认路径
            return f"{base_url}/open/base/data"
        
        # 直接返回完整路径
        return f"{base_url}{api_url}"
    
    def query_bank_list(self, request):
        """
        查询银行总行信息
        
        Args:
            request: BankListRequest实例
            
        Returns:
            BankListResponse实例
        """
        return self.post(request, BankListResponse)
    
    def query_bank_branch_list(self, request):
        """
        查询分支行信息
        
        Args:
            request: BankBranchListRequest实例
            
        Returns:
            BankBranchListResponse实例
        """
        return self.post(request, BankBranchListResponse)
    
    def query_mcc(self, request):
        """
        查询MCC信息
        
        Args:
            request: MccQueryRequest实例
            
        Returns:
            MccQueryResponse实例
        """
        return self.post(request, MccQueryResponse)
    
    def query_region_list(self, request):
        """
        查询地区码信息
        
        Args:
            request: RegionListRequest实例
            
        Returns:
            RegionListResponse实例
        """
        return self.post(request, RegionListResponse)
    
    def query_bank_card_bin(self, request):
        """
        查询银行卡bin信息
        
        Args:
            request: BankCardBinMatchingRequest实例
            
        Returns:
            BankCardBinMatchingResponse实例
        """
        return self.post(request, BankCardBinMatchingResponse) 